Simplify code by making in and out pointers internal to xenbus_xs.c
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Thu, 28 Jul 2005 12:25:13 +0000 (12:25 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Thu, 28 Jul 2005 12:25:13 +0000 (12:25 +0000)
Signed-off-by: Rusty Russel <rusty@rustcorp.com.au>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.h
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c

index f28fa37ee2cd727c96649389a60b76dffbce44bb..67d16434a554ea5c420e51dba804c3c53db2f9c5 100644 (file)
@@ -47,6 +47,17 @@ struct ringbuf_head
 
 DECLARE_WAIT_QUEUE_HEAD(xb_waitq);
 
+static inline struct ringbuf_head *outbuf(void)
+{
+       return machine_to_virt(xen_start_info.store_mfn << PAGE_SHIFT);
+}
+
+static inline struct ringbuf_head *inbuf(void)
+{
+       return machine_to_virt(xen_start_info.store_mfn << PAGE_SHIFT)
+               + PAGE_SIZE/2;
+}
+
 static irqreturn_t wake_waiting(int irq, void *unused, struct pt_regs *regs)
 {
        wake_up(&xb_waitq);
@@ -108,9 +119,10 @@ static int output_avail(struct ringbuf_head *out)
        return avail != 0;
 }
 
-int xb_write(struct ringbuf_head *out, const void *data, unsigned len)
+int xb_write(const void *data, unsigned len)
 {
        struct ringbuf_head h;
+       struct ringbuf_head *out = outbuf();
 
        do {
                void *dst;
@@ -141,24 +153,26 @@ int xb_write(struct ringbuf_head *out, const void *data, unsigned len)
        return 0;
 }
 
-int xs_input_avail(struct ringbuf_head *in)
+int xs_input_avail(void)
 {
        unsigned int avail;
+       struct ringbuf_head *in = inbuf();
 
        get_input_chunk(in, in->buf, &avail);
        return avail != 0;
 }
 
-int xb_read(struct ringbuf_head *in, void *data, unsigned len)
+int xb_read(void *data, unsigned len)
 {
        struct ringbuf_head h;
+       struct ringbuf_head *in = inbuf();
        int was_full;
 
        while (len != 0) {
                unsigned int avail;
                const char *src;
 
-               wait_event(xb_waitq, xs_input_avail(in));
+               wait_event(xb_waitq, xs_input_avail());
                h = *in;
                mb();
                if (!check_buffer(&h)) {
@@ -182,14 +196,14 @@ int xb_read(struct ringbuf_head *in, void *data, unsigned len)
        }
 
        /* If we left something, wake watch thread to deal with it. */
-       if (xs_input_avail(in))
+       if (xs_input_avail())
                wake_up(&xb_waitq);
 
        return 0;
 }
 
 /* Set up interrpt handler off store event channel. */
-int xb_init_comms(void **in, void **out)
+int xb_init_comms(void)
 {
        int err, irq;
 
@@ -202,11 +216,9 @@ int xb_init_comms(void **in, void **out)
                return err;
        }
 
-       *out = machine_to_virt(xen_start_info.store_mfn << PAGE_SHIFT);
-       *in = *out + PAGE_SIZE / 2;
-
        /* FIXME zero out page -- domain builder should probably do this*/
-       memset(*out, 0, PAGE_SIZE);
+       memset(machine_to_virt(xen_start_info.store_mfn << PAGE_SHIFT),
+              0, PAGE_SIZE);
 
        return 0;
 }
index 09678630003f6952ceb73720d0ba56b1698ea934..860c09c8954a51d8d63d1d392a49d51e2bada2e4 100644 (file)
@@ -2,13 +2,12 @@
 #ifndef _XENBUS_COMMS_H
 #define _XENBUS_COMMS_H
 int xs_init(void);
-int xb_init_comms(void **in, void **out);
+int xb_init_comms(void);
 
 /* Low level routines. */
-struct ringbuf_head;
-int xb_write(struct ringbuf_head *out, const void *data, unsigned len);
-int xb_read(struct ringbuf_head *in, void *data, unsigned len);
-int xs_input_avail(struct ringbuf_head *in);
+int xb_write(const void *data, unsigned len);
+int xb_read(void *data, unsigned len);
+int xs_input_avail(void);
 extern wait_queue_head_t xb_waitq;
 
 #endif /* _XENBUS_COMMS_H */
index 407449dd64e36fbfc278874900f89416cbd6bc40..3c39931a973f4bc17bd4196120720732e7c595c7 100644 (file)
@@ -44,7 +44,6 @@
 #define streq(a, b) (strcmp((a), (b)) == 0)
 
 static char printf_buffer[4096];
-static void *xs_in, *xs_out;
 static LIST_HEAD(watches);
 DECLARE_MUTEX(xenbus_lock);
 
@@ -69,7 +68,7 @@ static void *read_reply(enum xsd_sockmsg_type *type, unsigned int *len)
        void *ret;
        int err;
 
-       err = xb_read(xs_in, &msg, sizeof(msg));
+       err = xb_read(&msg, sizeof(msg));
        if (err)
                return ERR_PTR(err);
 
@@ -77,7 +76,7 @@ static void *read_reply(enum xsd_sockmsg_type *type, unsigned int *len)
        if (!ret)
                return ERR_PTR(-ENOMEM);
 
-       err = xb_read(xs_in, ret, msg.len);
+       err = xb_read(ret, msg.len);
        if (err) {
                kfree(ret);
                return ERR_PTR(err);
@@ -94,15 +93,14 @@ static void *read_reply(enum xsd_sockmsg_type *type, unsigned int *len)
 void xenbus_debug_write(const char *str, unsigned int count)
 {
        struct xsd_sockmsg msg;
-       void *out = machine_to_virt(xen_start_info.store_mfn << PAGE_SHIFT);
 
        msg.type = XS_DEBUG;
        msg.len = sizeof("print") + count + 1;
 
-       xb_write(out, &msg, sizeof(msg));
-       xb_write(out, "print", sizeof("print"));
-       xb_write(out, str, count);
-       xb_write(out, "", 1);
+       xb_write(&msg, sizeof(msg));
+       xb_write("print", sizeof("print"));
+       xb_write(str, count);
+       xb_write("", 1);
 }
 
 /* Send message to xs, get kmalloc'ed reply.  ERR_PTR() on error. */
@@ -123,12 +121,12 @@ static void *xs_talkv(enum xsd_sockmsg_type type,
        for (i = 0; i < num_vecs; i++)
                msg.len += iovec[i].iov_len;
 
-       err = xb_write(xs_out, &msg, sizeof(msg));
+       err = xb_write(&msg, sizeof(msg));
        if (err)
                return ERR_PTR(err);
 
        for (i = 0; i < num_vecs; i++) {
-               err = xb_write(xs_out, iovec[i].iov_base, iovec[i].iov_len);;
+               err = xb_write(iovec[i].iov_base, iovec[i].iov_len);;
                if (err)
                        return ERR_PTR(err);
        }
@@ -509,14 +507,14 @@ static int watch_thread(void *unused)
                char *token;
                char *node = NULL;
 
-               wait_event(xb_waitq, xs_input_avail(xs_in));
+               wait_event(xb_waitq, xs_input_avail());
 
                /* If this is a spurious wakeup caused by someone
                 * doing an op, they'll hold the lock and the buffer
                 * will be empty by the time we get there.               
                 */
                down(&xenbus_lock);
-               if (xs_input_avail(xs_in))
+               if (xs_input_avail())
                        node = xs_read_watch(&token);
 
                if (node && !IS_ERR(node)) {
@@ -548,7 +546,7 @@ int xs_init(void)
        int err;
        struct task_struct *watcher;
 
-       err = xb_init_comms(&xs_in, &xs_out);
+       err = xb_init_comms();
        if (err)
                return err;